package com.jin.api.v1;

import com.jin.Exception.http.NotFoundException;
import com.jin.model.Category;
import com.jin.model.GridCategory;
import com.jin.repository.GridCategoryRepository;
import com.jin.service.CategoryService;
import com.jin.service.GridCategoryService;
import com.jin.vo.CategoriesAllVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//分类的相关接口
@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    GridCategoryService gridCategoryService;
    @GetMapping("/all")
    public CategoriesAllVo getAll(){
        Map<Integer, List<Category>> categories = categoryService.getAll();
        //把hashMsp对象变成vo对象即可
        return new CategoriesAllVo(categories);
    }

    @GetMapping("/grid/all")
    public List<GridCategory> getGridCategoryList(){
        List<GridCategory> gridCategoryList = gridCategoryService.getGridCategoryList();
        if (gridCategoryList.isEmpty()){
            throw new NotFoundException(30009);
        }
        return gridCategoryList;
    }

}
